<?php

function getUserLevel($level){
	$level	=	intval($level);
	if($level>0){
		$info = D('SystemGroup')->where("id='$level'")->find();
		return '<font color="red">'.$info['name'].'</font>';
	}else{
		return '普通用户';
	}
}

function getInfoCate($id){
	$value = D('InfoCate')->where("id=".$id)->find();
	return $value['title'];
}

function formatsize($fileSize) {
	$size = sprintf("%u", $fileSize);
	if($size == 0) {
		return("0 Bytes");
	}
	$sizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
	return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizename[$i];

}

//删除目录
function rmdirr($dirname) {
	if (!file_exists($dirname)) {
		return false;
	}
	if (is_file($dirname) || is_link($dirname)) {
		return unlink($dirname);
	}
	$dir = dir($dirname);
	while (false !== $entry = $dir->read()) {
		if ($entry == '.' || $entry == '..') {
			continue;
		}
		rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
	}
	$dir->close();
	return rmdir($dirname);
}


function getCmsCateTitle($id){
	return D('CmsCate')->where("id=".$id)->getField('title');
}

//将二维数组格式化为一维数组
function formatArray($array, $field = 'id') {
	$res = array();
	foreach($array as $v) {
		$res[] = $v[$field];
	}
	return $res;
}

function getMultiUserName($uid){
	if(empty($uid)) return '';
	
	if(is_array($uid)){
		$uidArr = $uid;
	}else{
		$uidArr = explode(',', $uid);
	}	
	foreach ($uidArr as $v){
		if(empty($v)) continue;
		
		$name[] = getUserName($v);
	}
	
	$name = implode(',', $name);
	return $name;
}

//Tag名称  韦心红增加 2009-05-12
function getTagName($tagid){
	static $_tag;

	if(empty($_tag)){
		$list = M('x_tag')->field('tagid, tagname')->findAll();
		foreach ($list as $v){			
			$_tag[$v['tagid']] = $v['tagname'];
		}
	}
	
	return $tag[$tagid];
}

//过渡如123，456这样的数字串
function intMember($val){
	$isArr = is_array($val);
	
	if(!$isArr){
		$val = explode(',', $val);
	}
	
	foreach ($val as $k=>&$v){
		$v = intval($v);
		if(empty($v))	unset($val[$k]);
	}
	
	if($isArr){
		return $val;
	}

	return implode(',', $val);
}

//后台日志  韦心红增加 2010-5-29
function addLog($uid, $data, $temp, $type='admin'){
	return D('Log','admin')->addLog($uid, $data, $temp, $type);
}
?>